package com.newtouch.bxzs.business.message.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.newtouch.bxzs.business.config.MyLog;
import com.newtouch.bxzs.business.message.model.AdvertisementBO;
import com.newtouch.bxzs.business.message.model.AdvertisementVO;
import com.newtouch.bxzs.business.message.model.ChangeStatusVO;
import com.newtouch.bxzs.business.message.model.ModifyAdvertisementVO;
import com.newtouch.bxzs.business.message.service.AdvertisementService;
import com.newtouch.bxzs.common.base.response.BaseResponse;
import com.newtouch.bxzs.common.base.response.RespGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 广告（首页广告/启动页广告）管理的controller类
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2020/12/18 13:51</td>
 * <td>liman</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author liman
 * @version 1.0.0
 * @since 1.0.0
 */
@Api(tags = "广告管理")
@RestController
@SuppressWarnings("unchecked")
@RequestMapping("/advertisementController")
public class AdvertisementController {

    /**
     * 静态变量：系统日志
     */
    private static final Log logger = LogFactory.getLog(AdvertisementController.class);

    @Resource
    private AdvertisementService advertMessageService;

    @ApiOperation(value = "展示启动页广告（随机一条）")
    @PostMapping("/getAdvertisement")
    public BaseResponse<AdvertisementBO> getAdvertisement() {
        logger.info("APP展示启动页广告");
        return RespGenerator.returnOK(advertMessageService.getAdvertisement());
    }

    @ApiOperation(value = "查询启动页或者首页广告列表")
    @PostMapping("/getAdvertisementList")
    @MyLog(systemFunctionName = "广告管理", systemFunctionUrl = "/advertisementController/getAdvertisementList", userOperationType = 4, userOperationSummary = "查询广告列表")
    public BaseResponse<IPage<AdvertisementBO>> getAdvertisementList(@RequestBody AdvertisementVO advertisementVO) {
        logger.info("查询广告列表");
        return RespGenerator.returnOK(advertMessageService.getAdvertisementList(advertisementVO));
    }

    @ApiOperation(value = "App展示首页广告列表")
    @PostMapping("/getAdvertisementListOnApp")
    @MyLog(systemFunctionName = "广告管理", systemFunctionUrl = "/advertisementController/getAdvertisementListOnApp", userOperationType = 4, userOperationSummary = "展示首页广告列表")
    public BaseResponse<List<AdvertisementBO>> getAdvertisementListOnApp() {
        logger.info("App展示首页广告列表");
        return RespGenerator.returnOK(advertMessageService.getAdvertisementListOnApp());
    }

    @ApiOperation(value = "查看广告详情")
    @ApiImplicitParam(name = "advertisementId", value = "广告id", paramType = "String")
    @GetMapping("/getAdvertisementDetail")
    @MyLog(systemFunctionName = "广告管理", systemFunctionUrl = "/advertisementController/getAdvertisementDetail", userOperationType = 4, userOperationSummary = "查看广告详情")
    public BaseResponse<AdvertisementBO> getAdvertisementDetail(@RequestParam(value = "advertisementId") String advertisementId) {
        logger.info("查询广告详情");
        return RespGenerator.returnOK(advertMessageService.getAdvertisementDetail(advertisementId));
    }

    @ApiOperation(value = "根据advertisementId删除广告（可批量删除广告）")
    @PostMapping("/deleteAdvertisement")
    @MyLog(systemFunctionName = "广告管理", systemFunctionUrl = "/advertisementController/deleteAdvertisement", userOperationType = 3, userOperationSummary = "删除广告")
    public BaseResponse<AdvertisementBO> deleteAdvertisement(@RequestBody @ApiParam(name = "advertisementIds", value = "广告id集合") List<String> advertisementIds) {
        logger.info("删除广告");
        return RespGenerator.returnOK(advertMessageService.deleteAdvertisement(advertisementIds));
    }

    @ApiOperation(value = "新增或者修改首页广告或启动页广告")
    @PostMapping("/modifyAdvertisement")
    @MyLog(systemFunctionName = "广告管理", systemFunctionUrl = "/advertisementController/modifyAdvertisement", userOperationType = 2, userOperationSummary = "新增或者修改广告")
    public BaseResponse<String> modifyAdvertisement(@RequestBody ModifyAdvertisementVO modifyAdvertisementVO) {
        return RespGenerator.returnOK(advertMessageService.modifyAdvertisement(modifyAdvertisementVO));
    }

    @ApiOperation(value = "修改（启动页或首页）广告发布状态")
    @PostMapping("/changeAdvertisementState")
    @MyLog(systemFunctionName = "广告管理", systemFunctionUrl = "/advertisementController/changeAdvertisementState", userOperationType = 2, userOperationSummary = "修改广告发布状态")
    public BaseResponse<AdvertisementBO> changeAdvertisementState(@RequestBody ChangeStatusVO changeStatusVO) {
        logger.info("改变广告状态");
        return RespGenerator.returnOK(advertMessageService.changeAdvertisementState(changeStatusVO));
    }

}
